﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ZedGraph;

namespace erse253_homework
{
    public partial class Compare : BaseWindow
    {
        public Compare(double[,] histogramdata, bool cumulative, bool log)
        {
            InitializeComponent();
            Distribution1(histogramdata, "Cumulative Histogram", true, false);
            Distribution2(histogramdata, "Cumulative Histogram Log", true, true);
        }

        public Compare(double[,] histogramdata1, double[,] histogramdata2, bool cumulative, bool log)
        {
            InitializeComponent();
            Histogram1(histogramdata1, "Variable H", cumulative, log);
            Histogram2(histogramdata2, "Variable D", cumulative, log);
        }

        private void Histogram1(double[,] histogramdata, string text, bool cumulative, bool log)
        {

            double[] x;
            double[] cy;

            Chart distribution = new Chart();
            distribution.Histogram(histogramdata, out x, out cy, cumulative, log);

            FormatHistogramLeft(text, x, cy);
        }

        private void Histogram2(double[,] histogramdata, string text, bool cumulative, bool log)
        {

            double[] x;
            double[] cy;

            Chart distribution = new Chart();
            distribution.Histogram(histogramdata, out x, out cy, cumulative, log);
            FormatHistogramRight(text, x, cy);

        }

        private void FormatGraphLeft(string text, double[] x, double[] cy)
        {
            GraphPane pane = zedGraphControl1.GraphPane;
            pane.Title.Text = text;
            pane.XAxis.Title.Text = "Value";
            pane.YAxis.Title.Text = "Counts";
            LineItem myCurve = pane.AddCurve(text, x, cy, Color.Red);

            zedGraphControl1.AxisChange();
        }

        private void FormatHistogramLeft(string text, double[] x, double[] cy)
        {
            GraphPane pane = zedGraphControl1.GraphPane;
            pane.Title.Text = text;
            pane.XAxis.Title.Text = "Value";
            pane.YAxis.Title.Text = "Counts";
            BarItem myCurve = pane.AddBar(text, x, cy, Color.Red);

            zedGraphControl1.AxisChange();
        }

        private void FormatGraphRight(string text, double[] x, double[] cy)
        {
            GraphPane pane = zedGraphControl2.GraphPane;
            pane.Title.Text = text;
            pane.XAxis.Title.Text = "Value";
            pane.YAxis.Title.Text = "Counts";
            LineItem myCurve = pane.AddCurve(text, x, cy, Color.Red);

            zedGraphControl2.AxisChange();
        }

        private void FormatHistogramRight(string text, double[] x, double[] cy)
        {
            GraphPane pane = zedGraphControl2.GraphPane;
            pane.Title.Text = text;
            pane.XAxis.Title.Text = "Value";
            pane.YAxis.Title.Text = "Counts";
            BarItem myCurve = pane.AddBar(text, x, cy, Color.Red);

            zedGraphControl2.AxisChange();
        }

        private void Distribution1(double[,] histogramdata, string text, bool cumulative, bool log)
        {

            double[] x;
            double[] cy;

            Chart distribution = new Chart();
            distribution.Histogram(histogramdata, out x, out cy, cumulative, log);

            FormatGraphLeft(text, x, cy);
        }

        private void Distribution2(double[,] histogramdata, string text, bool cumulative, bool log)
        {
         
            double[] x;
            double[] cy;

            Chart distribution = new Chart();
            distribution.Histogram(histogramdata, out x, out cy, cumulative, log);
            FormatGraphRight(text, x, cy);
        }

    }
}
